package com.yxj.Test6Case;

import java.util.ArrayList;
import java.util.Collections;

public class MyThread extends Thread{
    ArrayList<Integer> list;

    //把抽奖箱抽到的奖存到集合中
    //抽奖箱1
    static ArrayList<Integer> list1 = new ArrayList<>();
    //抽奖箱2
    static ArrayList<Integer> list2 = new ArrayList<>();

    public MyThread(ArrayList<Integer> list) {
        this.list = list;
    }

    @Override
    public void run() {
        while(true) {
            synchronized (com.yxj.Test5Case.MyThread.class) {
                if(list.size() == 0) {
                    if ("抽奖池1".equals(getName())) {
                        System.out.println("抽奖池1"+list1);
                    } else {
                        System.out.println("抽奖池2"+list2);
                    }
                    break;
                }
                else {
                    //继续抽奖
                    Collections.shuffle(list);
                    int price = list.remove(0);
                    if("抽奖池1".equals(getName())) {
                        list1.add(price);
                    }else {
                        list2.add(price);
                    }
                }
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
